package com.tepth.appmanageservice.tools.ext;

import com.tepth.appmanageservice.protocol.Index;

public class ExtToInt {
	public static int from2bit(String l, String r) {
		return Integer.valueOf(l + r, 2);
	}

	public static short fromByteArrayTo16(byte[] data, Index index) {
		short iOutcome = 0;
		byte bLoop;

		for (int i = 0; i < 2; i++) {
			bLoop = data[index.get()];
			iOutcome += (bLoop & 0xFF) << (8 * i);
		}
		return iOutcome;
	}

	public static int fromByteArrayTo32(byte[] data, Index index) {
		int iOutcome = 0;
		byte bLoop;

		for (int i = 0; i < 4; i++) {
			bLoop = data[index.get()];
			iOutcome += (bLoop & 0xFF) << (8 * i);
		}
		return iOutcome;
	}

	public static int dateTimeConverter(byte b) {
		String year2bits = ExtToString.from2byte(b);

		String year_ten2bits = year2bits.substring(0, 4);
		String year_a2bits = year2bits.substring(4, 8);

		byte year_ten = (byte) Short.parseShort(year_ten2bits, 2);
		byte year_a = (byte) Short.parseShort(year_a2bits, 2);
		return year_ten * 10 + year_a;
	}
}